Skip to content

Replace Assert.IsTrue with CollectionAssert.AreEqual for collection comparisons#1730

Merged
Rob-Hague merged 7 commits into
developfrom
copilot/refactor-collection-assertions
Jun 26, 2026
Merged

Replace Assert.IsTrue with CollectionAssert.AreEqual for collection comparisons#1730
Rob-Hague merged 7 commits into
developfrom
copilot/refactor-collection-assertions

Conversation

Copilot AI commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

Brings the copilot/refactor-collection-assertions branch up to date with origin/develop (21 new commits) and checks whether any newly introduced test code warrants additional CollectionAssert conversions.

Changes

  • Merge origin/develop — incorporates upstream changes including in-place encryption, serialisation buffer work, cipher/AES refactors, and various dependency bumps
  • Conflict resolutionAbstractionsTest.cs had a using directive ordering conflict; resolved by keeping our version (body already contained all necessary directives, so the develop version's top-of-file additions would have been duplicates)
  • CollectionAssert scan — audited all newly merged test files; all Assert.AreEqual calls in the merged code compare scalar values (lengths, names, enums), so no new conversions are needed
Original prompt

find all places in tests where some collections are being asserted for equality, e.g. Assert.IsTrue(xxx.IsEqualTo(yyy)) or Assert.IsTrue(xxx.SequenceEqual(yyy)) and replace them with CollectionAssert.AreEqual. Pay attention to the order of arguments to CollectionAssert.AreEqual - the expected value is the first argument and the actual value is the second. If there is a separate assertion on the collections' lengths, then remove it since CollectionsAssert.AreEqual takes care of that as well


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Replace Assert.IsTrue(xxx.IsEqualTo(yyy)) and Assert.IsTrue(xxx.SequenceEqual(yyy))
with CollectionAssert.AreEqual(expected, actual) across 55 test files

Co-authored-by: Rob-Hague <5132141+Rob-Hague@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor collection assertions to use CollectionAssert.AreEqual Replace Assert.IsTrue with CollectionAssert.AreEqual for collection comparisons Nov 4, 2025
Copilot AI requested a review from Rob-Hague November 4, 2025 07:54

@Rob-Hague Rob-Hague left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot there are multiple build errors of the form "Using directive is unnecessary", and some review comments to address:

Comment thread test/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeInitMessageTest.cs Outdated
…y using directives

- Fixed argument order in KeyExchangeDhGroupExchangeReplyTest.cs (expected first, actual second)
- Fixed argument order in KeyExchangeInitMessageTest.cs (expected first, actual second)
- Removed unnecessary 'using System.Linq' directives from all affected test files

Co-authored-by: Rob-Hague <5132141+Rob-Hague@users.noreply.github.com>

Copilot AI commented Nov 13, 2025

Copy link
Copy Markdown
Contributor Author

@copilot there are multiple build errors of the form "Using directive is unnecessary", and some review comments to address:

Fixed in commit 2821526. All IDE0005 warnings have been resolved by removing unnecessary using directives, and the argument order issues in the review comments have been corrected. The build now succeeds with 0 warnings and 0 errors.

@Rob-Hague Rob-Hague marked this pull request as ready for review November 13, 2025 21:31
@Rob-Hague

Copy link
Copy Markdown
Collaborator

@copilot resolve conflicts

Copilot AI commented Nov 14, 2025

Copy link
Copy Markdown
Contributor Author

@copilot resolve conflicts

Conflicts resolved in commit 8e5e1bd. Merged develop branch and resolved conflicts in 2 test files by adopting Assert.HasCount from develop while keeping CollectionAssert.AreEqual for collection comparisons. Build succeeds with 0 warnings and 0 errors.

…-collection-assertions

# Conflicts:
#	test/Renci.SshNet.Tests/Classes/ShellStreamTest_Write_WriteBufferNotEmptyAndWriteLessBytesThanBufferCanContain.cs
#	test/Renci.SshNet.Tests/Classes/ShellStreamTest_Write_WriteBufferNotEmptyAndWriteMoreBytesThanBufferCanContain.cs
@Rob-Hague Rob-Hague force-pushed the copilot/refactor-collection-assertions branch from 8e5e1bd to b8a5836 Compare November 14, 2025 21:24
…-collection-assertions

# Conflicts:
#	test/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpDataResponseTest.cs
@drieseng

drieseng commented Feb 8, 2026

Copy link
Copy Markdown
Member

Isn't CollectionAssert sort of deprecated?

@Rob-Hague

Copy link
Copy Markdown
Collaborator

I don't know, but it prints nice error messages

This was mostly just a copilot test

@WojciechNagorski

Copy link
Copy Markdown
Collaborator

Good enough. These days, you can change the entire framework in a single day, so if it provides benefits, it's fine.

Copilot AI changed the title Replace Assert.IsTrue with CollectionAssert.AreEqual for collection comparisons Merge develop into refactor-collection-assertions; scan for new CollectionAssert opportunities Jun 26, 2026
@Rob-Hague Rob-Hague changed the title Merge develop into refactor-collection-assertions; scan for new CollectionAssert opportunities Replace Assert.IsTrue with CollectionAssert.AreEqual for collection comparisons Jun 26, 2026
@Rob-Hague Rob-Hague merged commit 41053cb into develop Jun 26, 2026
7 checks passed
@Rob-Hague Rob-Hague deleted the copilot/refactor-collection-assertions branch June 26, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants